package com.oms;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.ecbt.rest.util.ExcelHelper;

public class GenerateJson {

	public static void main(String[] args) {
		
		// Map<String, String> countryMap = readCountry();
		
		File newFile = new File("D:\\AijunTao\\Desktop\\工作簿1.xlsx");
		// 读取excel
		List<List> resultList = new ArrayList<List>();
		try {
			resultList = ExcelHelper.readExcel2List(newFile);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		List<OmsDealerReq> boxes = new ArrayList<>();
		for(int i = 1;i < resultList.size();i++){
			OmsDealerReq box = new OmsDealerReq();
			List one = (List)resultList.get(i);
			String dealerType = one.get(7).toString();
			
//			if(dealerType.equals("10130010")) {
				box.setDealerCode(one.get(0).toString());
				box.setDealerName(one.get(1).toString());
				box.setDealerShortName(one.get(2)==null?"":one.get(2).toString());
				box.setDealerNameForDoc(one.get(3)==null?"":one.get(3).toString());
				box.setDealerAddr(one.get(4)==null?"":one.get(4).toString());
				// box.setCountry(countryMap.get(one.get(6).toString()));
				box.setCountry(one.get(6)==null?"":one.get(6).toString());
				box.setShortCode(one.get(8)==null?"":one.get(8).toString());
				box.setCurrency(one.get(10)==null?"":one.get(10).toString());
				
				box.setState(Long.parseLong(one.get(13).toString()));
				box.setDealerType(Long.parseLong(dealerType));
				box.setTenantId(1);
				boxes.add(box);
//			}
			
		}
		System.out.println(JSONObject.toJSON(boxes));
		System.out.println();
	}
	
	private static Map<String, String> readCountry() {
		Map<String, String> map = new HashMap<>();
		File newFile = new File("D:\\AijunTao\\Desktop\\OMS上线初始化数据\\国家.xlsx");
		// 读取excel
		List<List> resultList = new ArrayList<List>();
		try {
			resultList = ExcelHelper.readExcel2List(newFile);
		} catch (Exception e) {
		}
		for(int i = 0;i < resultList.size();i++){
			List one = (List)resultList.get(i);
			map.put(one.get(0).toString(), one.get(1).toString());
		}
		return map;
	}

	public void generatePort() {
		File newFile = new File("D:\\AijunTao\\Desktop\\OMS上线初始化数据\\港口.xlsx");
		// 读取excel
		List<List> resultList = new ArrayList<List>();
		try {
			resultList = ExcelHelper.readExcel2List(newFile);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		List<OmsPortReq> boxes = new ArrayList<>();
		for(int i = 0;i < resultList.size();i++){
			OmsPortReq box = new OmsPortReq();
			List one = (List)resultList.get(i);
			box.setDelFlag("0");
			box.setRemark("");
			box.setPortName(one.get(2).toString());
			box.setSapCode(one.get(1).toString());
			boxes.add(box);
		}
		System.out.println(JSONObject.toJSON(boxes));
		System.out.println();
	}
}
